/*
 * SELECT id, userNo, username, password, email, mobileNo, telNo, state
 * FROM t_mgmt_user
 * LIMIT 20, 20
 */
package com.honeybees.framework.pagination.dialect.impl;

import com.alibaba.druid.sql.PagerUtils;
import com.alibaba.druid.util.JdbcConstants;
import com.honeybees.framework.pagination.dialect.Dialect;

/**
 * <dl>
 * <dt><b> MySQL分页查询SQL语句 </b></dt>
 * <p>
 * <dd>功能描述</dd>
 * </dl>
 * <p>
 * Copyright (C) All rights reserved.
 * </p>
 *
 * @author 李远明
 * @version 2017-04-08 20:30
 * @since 2015-10-23 23:11:30
 */
public class MySQLDialect extends AbstractDialect {

    protected static final String SQL_END_DELIMITER = ";";

    /**
     * {@inheritDoc}
     *
     * @version 2015-10-23 23:11:30 新建
     * @version 2015-12-14 11:46:46 {@link PagerUtils#limit(String, String, int, int)}
     */
    // @Override
    public String getPageSql(String querySql, int offset, int limit) {
        querySql = querySql.trim();

        String pageSql = PagerUtils.limit(querySql, JdbcConstants.MYSQL, offset, limit);
        return pageSql;
    }

    /**
     * {@inheritDoc}
     *
     * @author 李远明
     * @version 2016年7月20日 下午8:54:28
     */
    @Override
    public String getCountSql(String querySql) {
        String countSql = PagerUtils.count(querySql, JdbcConstants.MYSQL);
        return countSql;
    }

    public static void main(String[] args) {
        String querySql = "SELECT id,userNo,username,password,email,mobileNo,telNo,state FROM t_mgmt_user WHERE state=?";
        Dialect instance = new MySQLDialect();
        String pageSql0 = instance.getPageSql(querySql, 0, 20);
        String pageSqlN = instance.getPageSql(querySql, 20, 20);
        System.out.println("--limit0: \n" + pageSql0);
        System.out.println("--limitN: \n" + pageSqlN);
    }

}
